import Vue from 'vue'
import Router from 'vue-router'

export const constantRoutes = [
  {
    path: '/',
    name: '',
    meta: { title: '登录' },
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'login',
    meta: { title: '登录' },
    component: (resolve) => require(['@/views/login'], resolve),
    // redirect: '/login',
  },

  {
    path: '/home',
    name: 'home',
    component: (resolve) => require(['@/views/home/home.vue'], resolve),
    meta: {},
    children: [
      {
        path: 'order',
        component: (resolve) => require(['@/views/order'], resolve),
        name: '我的',
      },
      {
        path: 'goods/:type',
        component: (resolve) => require(['@/views/goods'], resolve),
        name: 'Goods',
      },
      {
        path: 'addGood/:type',
        component: (resolve) => require(['@/views/addGood'], resolve),
        name: 'AddGood',
      },
      {
        path: '/category',
        component: (resolve) => require(['@/views/category'], resolve),
        name: 'GoodCategory',
      },
      {
        path: 'ownerlist',
        component: (resolve) => require(['@/views/ownerlist'], resolve),
        name: 'ManagerList',
      },
      {
        path: 'ownerreq',
        component: (resolve) => require(['@/views/ownerreq'], resolve),
        name: 'ManagerReqList',
      },
      {
        path: 'ownerorder',
        component: (resolve) => require(['@/views/ownerorder'], resolve),
        name: 'ManagerOrder',
      },
      {
        path: 'tradeinfo',
        component: (resolve) => require(['@/views/tradeinfo'], resolve),
        name: 'TradeInfo',
      },
      {
        path: 'tradelist',
        component: (resolve) => require(['@/views/tradelist'], resolve),
        name: 'TradeList',
      },
      {
        path: 'data',
        component: (resolve) => require(['@/views/data'], resolve),
        name: 'DataCom',
      },
    ],
  },
]

//防止连续点击多次路由报错
let routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((err) => err)
}
Vue.use(Router)

export default new Router({
  base: process.env.VUE_APP_APP_NAME ? process.env.VUE_APP_APP_NAME : '/',
  mode: 'history', //去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
})
